package com.cskaoyan.kpi.peak;

import com.cskaoyan.kpi.Summary;
import com.cskaoyan.kpi.output.MysqlOutputFormat;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;

import java.io.IOException;

/**
 * @ClassName DailyHourPeak
 * @Description:
 * 最后生成的数据因为时间比较均匀，没有明显的统计学意义
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/17 9:07
 * @Version V1.0
 **/
public class DailyHourPeak {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration(true);
        Job job = Job.getInstance(configuration);

        job.setJobName("daily-hour-peak");
        job.setJarByClass(DailyHourPeak.class);
        job.addArchiveToClassPath(new Path("/lib/mysql/mysql-connector-java-5.1.47.jar"));
        TextInputFormat.addInputPath(job, new Path(args[0]));

        job.setMapperClass(DailyHourPeakMapper.class);
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(Text.class);

        job.setReducerClass(DailyHourPeakReducer.class);
        job.setOutputKeyClass(Summary.class);
        job.setOutputValueClass(Text.class);
        job.setOutputFormatClass(MysqlOutputFormat.class);

        job.waitForCompletion(true);
    }
}
